﻿using Microsoft.Devices;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Networking.Proximity;

namespace Indt.Components
{
    public static class DeviceInfo
    {
        public static string UniqueIDBase64Signed()
        {
            byte[] _device = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
            return BitConverter.ToInt64(_device, 0).ToString();
        }

        public static string UniqueIDBase32Signed()
        {
            byte[] _device = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
            return BitConverter.ToInt32(_device, 0).ToString();
        }

        public static string UniqueIDBase32Unsigned()
        {
            Int64 n = BitConverter.ToInt32((byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId"), 0);
            if (n < 0)
            {
                return ((Int64)(Math.Abs(n)) + (Int64)((Int64)Math.Pow(2, 32))).ToString();
            }
            return n.ToString();
        }

        public static string DeviceModel()
        {
            string model = null;
            object theModel = null;

            if (Microsoft.Phone.Info.DeviceExtendedProperties.TryGetValue("DeviceName", out theModel))
                model = theModel as string;

            return model;
        }

        public static Guid GenerateNewGuid() {
            return System.Guid.NewGuid();
        }

        public static Double getApplicationDeviceCurrentMemoryUsage() {
            Double currentMemoryUsage = 0;
            try
            {
                currentMemoryUsage = Convert.ToDouble((Int64)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage"));
            }
            catch (Exception e) {
            #if DEBUG
                Debug.WriteLine(e.Message);
            #endif
                currentMemoryUsage = -1;
            }
            return currentMemoryUsage;
        }

        public static Double getDeviceTotalMemory()
        {
            Double totalMemory = 0;
            try
            {
                totalMemory = Convert.ToDouble((Int64)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceTotalMemory"));
            }
            catch (Exception e)
            {
            #if DEBUG
                Debug.WriteLine(e.Message);
            #endif
                totalMemory = -1;
            }
            return totalMemory;
        }

        public static int getBatteryLevelPercent() {
            return Windows.Phone.Devices.Power.Battery.GetDefault().RemainingChargePercent;
        }

        public static TimeSpan getBatteryTimeRemainder() {
            return Windows.Phone.Devices.Power.Battery.GetDefault().RemainingDischargeTime;
        }
       
        public static Boolean IsDeviceHasFrontCamera() {
            
            
            return PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing);
 
        }

      
    }
}